package tleng_tp;

public final class Unit implements Comparable<Unit>  {
	private String name;
	
	private int power;
	
	public String getName(){ return name;}
	
	public int getPower(){ return power;}
	
	public void setPower(int value){ 
		power = value; 
	}
	
	public Unit(String unitName){
		this(unitName, 1);
	}
	
	public Unit(String unitName, int unitPower) throws NullPointerException{
		if(unitName == null)
			throw new NullPointerException("unit name should not be null");
		name = unitName;
		power = unitPower;
	}
	
    public int hashCode() {
        return name.hashCode() + power;
    }

    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (obj == this)
            return true;
        if (obj.getClass() != getClass())
            return false;

        Unit other = (Unit) obj;
        return other.name.equals(name) && other.getPower() == power;
    }	
    
    public String toString(){
    	return name + "^" + power;    	
    }
    
    public int compareTo(Unit o) {
        return name.compareTo(o.getName());
    }    
}
